#include <iostream>
#include <cstring>
#include <queue>

using namespace std;

const int N = 1010;
int edges[N][N];
int n, m;

int st[N];

void bfs(int u)
{
	st[u] = true;
	cout << u << " ";
	for(int v = 1; v <= n; v++)
	{
		if(edges[v][u] != -1 && !st[u])
		{
			dfs(u);
		}
	}
} 

void bfs()
{
	queue<int> q;
	q.push(1);
	st[1] = true;
	while(q.size())
	{
		auto u = q.front(); q.pop();
		cout << u << " ";
		for(int v = 1; v <= n; v++)
		{
			if(edges[u][v] != -1 && !st[v])
			{
				q.push(v);
				st[v] = true;
			}
		}
	}
}

int main()
{
	memset(edges, -1, sizeof egdes);
	cin >> n >> m;
	for(int i = 1; i <= m; i++)
	{
		int a, b, c;
		edges[a][b] = c; edges[b][a] = c;
	}
	dfs(1);
	bfs();
	return 0;
} 
